package com.mitdy.sg.data.enumeration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.mitdy.sg.common.utils.BeanMapUtils;

public enum GameType {

    TYPE_1(1, "篮球"), TYPE_2(2, "足球");

    private Integer code;
    private String name;

    private GameType(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static String getNameByCode(Integer code) {
        if (code == null) {
            return "";
        }

        GameType[] values = GameType.values();
        for (GameType type : values) {
            if (type.getCode().equals(code)) {
                return type.getName();
            }
        }

        return "";
    }

    public static List<Map<String, Object>> getElements() {
        GameType[] values = GameType.values();
        List<Map<String, Object>> elements = new ArrayList<Map<String, Object>>(values.length);
        for (GameType type : values) {
            try {
                elements.add(BeanMapUtils.toMap(type));
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }

        return elements;
    }

}
